package com.tlgen.controller.Institute;

import com.tlgen.model.Labor;
import com.tlgen.model.RespBean;
import com.tlgen.service.LaborService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: tlgen
 * @Discription:
 */
@RestController
@RequestMapping("/institute/labor")
public class LaborController {

    @Autowired
    LaborService laborService;

    @GetMapping("/")
    public List<Labor> getAllLabors() {
        return laborService.getAllLabors();
    }

    @PostMapping("/")
    public RespBean addLabor(@RequestBody Labor Labor) {
        if (laborService.addLabor(Labor) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @PutMapping("/")
    public RespBean updateLabor(@RequestBody Labor Labor) {
        if (laborService.updateLabor(Labor) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteLaborById(@PathVariable Integer id) {
        if (laborService.deleteLaborById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @DeleteMapping("/")
    public RespBean deleteLaborByIds(Integer[] ids) {
        if (laborService.deleteLaborByIds(ids) == ids.length) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }
}
